package com.shenmazong.serverloginqq.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @author 田不平
 * @project server-security
 * @date 2020/4/28 9:34 AM
 * http://www.shenmazong.com
 */
@Slf4j
@Controller
@CrossOrigin
public class LoginController {

//    APP ID：101874060
//    APP Key：8affd2651ec502d2238c8212e5e687d9


    @GetMapping(value = "/login")
    public String login(){
        return "login";
    }

    @GetMapping(value = "/qqlogin")
    public String qqlogin() {
        log.info("qqlogin 被回调了....");
        return "index";
    }

    @PostMapping(value = "/doLogin")
    @ResponseBody
    public Object doLogin(HttpServletRequest request) {
        Map<String,Object> resultMap = new HashMap<>();

        String openId = request.getParameter("openId");
        String accessToken = request.getParameter("accessToken");
        String nick = request.getParameter("nick");
        String headurl = request.getParameter("headurl");
        String gender = request.getParameter("gender");

        log.info("openId:"+openId);
        log.info("accessToken:"+accessToken);
        log.info("nick:"+nick);
        log.info("headurl:"+headurl);
        log.info("gender:"+gender);

        resultMap.put("result", 0);

        return resultMap;
    }

    // /Users/hm/.m2/repository/

}
